home *** CD-ROM | disk | FTP | other *** search
- #pragma pack(2)
- #include <Common.h>
- #include <System/SysAll.h>
- #include <UI/UIAll.h>
- #include <SerialMgr.h>
- #include <System/SysEvtMgr.h>
-
- #define NON_PORTABLE
- #define asm
- #include <Hardware/Hardware.h>
-
-
- Word *LCDX = (Word *) 0xFFFFFA18;
- Word *LCDY = (Word *) 0xFFFFFA1A;
- Word *LCDWH = (Word *) 0xFFFFFA1C;
- Byte *LCDBL = (Byte *) 0xFFFFFA1F;
-
- UInt16 SerL;
-
- void setup()
- {
- SerSettingsType serSettings;
-
- #define BAUD 1200
-
- SerOpen(SerL, 0, BAUD);
-
- SerGetSettings(SerL, &serSettings);
- serSettings.flags = serSettingsFlagBitsPerChar8 | serSettingsFlagStopBits1;
- SerSetSettings(SerL, &serSettings);
-
- *LCDX = 0x8000 + 80;
- *LCDY = 80;
- *LCDWH = 0x0404;
- *LCDBL = 0x88;
- }
-
- void teardown()
- {
- SerClose(SerL);
- *LCDX &= 0x3fff;
- }
-
- void dokatt()
- {
- char buf[4];
- int x, y, b;
- int x0, y0;
-
- SerReceive10(SerL, buf, 3, -1);
-
- if (!(buf[0] & 0x40)) {
- while (!(buf[0] & 0x40))
- SerReceive10(SerL, buf, 1, -1);
- SerReceive10(SerL, &buf[1], 2, -1);
- }
-
- b = buf[0] & 0x30; /* 0x20 is button 1 */
- x = ((buf[0] & 3) << 14) | ((buf[1] & 0x3f) << 8);
- y = ((buf[0] & 0x0c) << 12) | ((buf[2] & 0x3f) << 8);
-
- #define SCALE 10
-
- x >>= SCALE;
- y >>= SCALE;
-
-
-
- x0 = (*LCDX & 0xff) + x;
- if (x0 < 0)
- x0 = 0;
- if (x0 > 159)
- x0 = 159;
-
- if (x0 > 156)
- *LCDWH = 4 + ((160 - x0) << 8);
- else
- *LCDWH = 0x0404;
- *LCDX = (0x8000 | x0);
-
-
-
- y0 = *LCDY + y;
- if (y0 < 0)
- y0 = 0;
- if (y0 > 159)
- y0 = 159;
- *LCDY = y0;
-
-
-
- if (b & 0x20) {
- RectangleType r = { {x0, y0}
- , {4, 4}
- };
-
- WinDrawRectangle(&r, 0);
- }
-
- if (b & 0x10) {
- RectangleType r = { {x0, y0}
- , {4, 4}
- };
-
- WinEraseRectangle(&r, 0);
- }
-
- }
-
-
- DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
- {
- short err;
- long full;
- EventType event;
-
-
- if (cmd != sysAppLaunchCmdNormalLaunch)
- return 0;
-
- SysLibFind("Serial Library", &SerL);
-
- setup();
-
- do {
- EvtGetEvent(&event, 0);
-
- EvtResetAutoOffTimer();
-
- if (SerReceiveCheck(SerL, &full))
- SerClearErr(SerL);
-
- if (full >= 3)
- dokatt();
-
- if (event.eType == nilEvent)
- continue;
-
-
- if (SysHandleEvent(&event))
- continue;
- if (MenuHandleEvent((void *) 0, &event, &err))
- continue;
-
- } while (event.eType != appStopEvent);
-
- teardown();
-
- return 0;
- }
-